import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

	Scanner in;
	PrintWriter out;

	void solve() {
		int n = in.nextInt();
		int cost[][] = new int[n][n];
		int count[][] = new int[n][n];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				count[i][j] = 1;
			}
		}
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				int value = in.nextInt();
				if (i != j && value == 0) {
					value = Integer.MAX_VALUE / 5;
				}
				cost[i][j] = value;
			}
		}
		for (int k = 0; k < n; k++) {
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < n; j++) {
					if (cost[i][k] + cost[k][j] < cost[i][j]) {
						cost[i][j] = cost[i][k] + cost[k][j];
						count[i][j] = count[i][k] + count[k][j];
					} else if (cost[i][k] + cost[k][j] == cost[i][j]) {
						if (count[i][k] + count[k][j] < count[i][j]) {
							count[i][j] = count[i][k] + count[k][j];
						}
					}
				}
			}
		}
		out.println(cost[0][n - 1] + " " + (count[0][n - 1] - 1));
	}

	void run() {
		in = new Scanner(System.in);
		out = new PrintWriter(System.out);
		try {
			solve();
		} finally {
			out.close();
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}

}
